const dbutil = require('../../../libs/MyDB');

module.exports = {
    getOrderInfo: async function () {
        let orders = [];
        await dbutil.multiSelect('res_orderinfo', '*')
            .then(
                result => {
                    orders = result;
                }
            )
        for(let i =0;i<orders.length;i++){
            let date = new Date(orders[i].order_time);
            let y = date.getFullYear();
            let m = date.getMonth()+1;
            let d = date.getDate();
            let time = `${y}-${m<10?'0'+m:m}-${d<10?'0'+d:d}`;
            orders[i].order_time = time;
        }
        return {
            code: 0,
            msg: "查询成功",
            data: orders,
            count: orders.length,
        }
    },
    delOrder: async function(data){
        await dbutil.del('res_order',`order_id=${data.order_id}`);

        return {
            code:200,
            msg: '删除成功',
        }
    },
    getOrderSelect: async function(selectId){
        let orderFoods = [];
        let sql = `select res_food.*,res_order_food.food_count,res_order_food.food_price from res_order_food LEFT JOIN res_food on res_order_food.food_id = res_food.food_id where order_id = ${selectId}`;
        await dbutil.sqlSelect(sql)
            .then(
                result => {
                    orderFoods = result;
                }
            )
        return {
            code: 0,
            msg: "查询成功",
            data: orderFoods,
            count: orderFoods.length,
        }
    }
}